package cn.wolfcode.wms.web.controller;

import cn.wolfcode.wms.domain.StockIncomeBill;
import cn.wolfcode.wms.qo.OrederbillQuery;
import cn.wolfcode.wms.qo.StockIncomeBillQuery;
import cn.wolfcode.wms.service.IStockIncomeBillService;
import cn.wolfcode.wms.service.IDepotService;
import cn.wolfcode.wms.util.JSONResult;
import cn.wolfcode.wms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("stockIncomebill")
public class StokIncomeBillController {
    @Autowired
    private IStockIncomeBillService stockIncomebillService;
    @Autowired
    private IDepotService depotService;
    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo")StockIncomeBillQuery qo){

        PageResult result = stockIncomebillService.queryForList(qo);

        model.addAttribute("result",result);
        //供应商
        model.addAttribute("depots",depotService.selectall());
        return "stockIncomebill/list";
    }

    @RequestMapping("input")
    public String input(Model model,Long id){
        if (id != null) {
            StockIncomeBill entity = stockIncomebillService.get(id);
            System.out.println(entity);
            model.addAttribute("entity",entity);
        }
        //供应商
        model.addAttribute("depots",depotService.selectall());
        return "stockIncomebill/input";
    }
    //查看视图
    @RequestMapping("listView")
    public String listView(Model model,Long id){
        if (id != null) {
            StockIncomeBill entity = stockIncomebillService.get(id);

            model.addAttribute("entity",entity);
        }
        //供应商

        return "stockIncomebill/listView";
    }
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StockIncomeBill entity){
        //在SpringMvc中对集合传值,需要索引
       stockIncomebillService.saveOrUpdate(entity);
        return new JSONResult();
    }
    @ResponseBody
    @RequestMapping("delete")
    public Object delete(Long id){

       stockIncomebillService.delete(id);
        JSONResult json = new JSONResult();
        return json;
    }

    @ResponseBody
    @RequestMapping("audit")
    public Object audit(Long id){

        stockIncomebillService.audit(id);
        JSONResult json = new JSONResult();
        return json;
    }
}
